
package fileby.gui.breadcrumbs;

import com.google.inject.Inject;
import fileby.core.IDisplayableFileSource;
import java.util.LinkedList;

/**
 *
 * @author Jacob
 */
public class BreadCrumbsPanel extends javax.swing.JPanel {

    private IBreadCrumbProvider breadCrumbProvider;

    @Inject
    public BreadCrumbsPanel(IBreadCrumbProvider breadCrumbProvider) {
        this.breadCrumbProvider = breadCrumbProvider;
        initComponents();
    }

    // Updates all breadcrumbs, giving each a directory to represent.
    public void update(IDisplayableFileSource current) {
        removeAll();
        LinkedList<IDisplayableFileSource> sources = new LinkedList();
        IDisplayableFileSource parentSource = current.getParent();
        while(parentSource != null){
            sources.addFirst(parentSource);
            parentSource = parentSource.getParent();
        }
        // Add the parents
        for(IDisplayableFileSource source : sources)
            add(breadCrumbProvider.create(source));

        // Add this source
        add(breadCrumbProvider.create(current));
        validate();
        repaint();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setMaximumSize(new java.awt.Dimension(1000, 40));
        setMinimumSize(new java.awt.Dimension(100, 40));
        setPreferredSize(new java.awt.Dimension(300, 40));
        setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEADING));
    }// </editor-fold>

}
